<?php

namespace app\common\model;

use think\facade\Db;
use think\Model;

class ModelBase extends Model
{
    protected $autoWriteTimestamp = true;
    protected $deleteTime = 'delete_time';
    protected $defaultSoftDelete = 0;

    /**
     * @param array $data
     * @return array|mixed
     * 根据数据库表过滤字段
     */
    final function createda($data = [])
    {
        $fields = Db::getTableFields($this->getTable());
        foreach ($data as $key => $val) {
            if (!in_array($key, $fields)) {
                unset($data[$key]);
            } elseif (is_string($val)) {
                $data[$key] = stripslashes($val);
            }
        }
        return $data;
    }
}